package com.tynet.tydemo.wxapi;


import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.activity.WXResultActivity;
import com.app.utiles.other.Constant;
import com.app.utiles.other.DLog;
import com.app.utiles.other.ToastUtile;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;

public class WXPayEntryActivity extends WXResultActivity {

    private static final String TAG = "WXPayEntryActivity";


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initWx(Constant.WX_APP_ID);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);

    }

    @Override
    public void onReq(BaseReq req) {
    }

    @Override
    public void onResp(BaseResp resp) {

        if (resp.getType() != ConstantsAPI.COMMAND_PAY_BY_WX) {
            Log.e(TAG, "支付发生错误");
            return;
        }
        String hint = "";
        int type = resp.errCode;
        switch (type) {
            case 0:
                //成功	展示成功页面
                hint = "支付成功";
                break;
            case -1:
                //支付错误
                hint = "支付错误";
                break;
            case -2:
                //用户取消支付
                hint = "支付取消";
                break;
        }
        ToastUtile.showToast(hint);
        finish();
        DLog.e(TAG, "支付结果：" + type + " " + resp.errStr + " " + resp.transaction);

    }
}